package test_005;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.util.HashMap;

import javax.swing.JFrame;


import net.sf.jasperreports.engine.JREmptyDataSource;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.util.JRLoader;
import net.sf.jasperreports.view.JRViewer;

public class TestJasper {

	/**
	 * @param args
	 * @throws JRException 
	 * @throws FileNotFoundException 
	 */
	public static void main(String[] args) throws JRException, FileNotFoundException {
		// TODO Auto-generated method stubd
		String reportJrxml = "D:\\software\\eclipse 3.6\\trunk_1_4_1\\test_01\\reportTemplate\\report2.jasper";
		Connection connection = null;
			
			try {
				Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
				 connection = DriverManager 
				.getConnection("jdbc:sqlserver://localhost:1433;databaseName=test","sa","111111");
			}catch (Exception e) {
				
			}
		InputStream is = new FileInputStream(reportJrxml);
        JasperReport jp = (JasperReport) JRLoader.loadObject(is);
		String desFile = "D:\\software\\eclipse 3.6\\trunk_1_4_1\\test_01\\reportTemplate\\report2.jasper";
//		JasperReport jp = JasperCompileManager.compileReport(reportJrxml);
		JasperPrint jasperPrint = JasperFillManager.fillReport(jp, new HashMap(), connection);
		JRViewer jr = new JRViewer(jasperPrint);
        JFrame jf = new JFrame();  
        jf.add(jr);  
        jf.pack();  
        jf.setSize(1024, 600);  
        jf.setVisible(true);  
		JasperExportManager.exportReportToHtmlFile(jasperPrint,"c:\\a.html");
	}

}
